package AutoResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class Tuling {
	public static String autoRespon(String requestString,long userid) throws IOException { 
        String APIKEY = "a11adea24eb54b52b642445d9008b5c1"; 
        String INFO = URLEncoder.encode(requestString, "utf-8"); 
        String getURL = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO+"&userid="+userid; 
        URL getUrl = new URL(getURL); 
        HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection(); 
        connection.connect(); 

        // 取得输入流，并使用Reader读取 
        BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream(), "utf-8")); 
        StringBuffer sb = new StringBuffer(); 
        String line = ""; 
        while ((line = reader.readLine()) != null) { 
            sb.append(line); 
        } 
        reader.close(); 
        // 断开连接 
        connection.disconnect(); 
        return sb.toString();
    }
	public static void main(String[] args) throws IOException {
		System.out.println(Tuling.autoRespon("最近热门电影", 1001010));
	}
}
